package com.swas.controller;

import com.github.pagehelper.PageInfo;
import com.swas.entity.PatrolPoint;
import com.swas.service.PatrolPointService;
import com.swas.util.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/patrolPoint")
public class PatrolPointController {

    @Autowired
    private PatrolPointService patrolPointService;

    @GetMapping
    public ResultVO list(
            Integer pageNum,
            Integer pageSize,
            String pointno,
            String pointname,
            String address
    ) {
        PageInfo<PatrolPoint> pageInfo = patrolPointService.list(pageNum, pageSize, pointno, pointname, address);
        return ResultVO.success(pageInfo);
    }

    @GetMapping("/all")
    public ResultVO all() {
        List<PatrolPoint> list = patrolPointService.all();
        return ResultVO.success(list);
    }

    @PostMapping
    public ResultVO addPatrolPoint(@RequestBody PatrolPoint patrolPoint) {
        patrolPointService.add(patrolPoint);
        return ResultVO.success();
    }

    @PutMapping
    public ResultVO updatePatrolPoint(@RequestBody PatrolPoint patrolPoint) {
        patrolPointService.update(patrolPoint);
        return ResultVO.success();
    }

    @DeleteMapping("/{id}")
    public ResultVO deletePatrolPoint(@PathVariable Integer id) {
        patrolPointService.delete(id);
        return ResultVO.success();
    }

    @GetMapping("/task/{taskId}")
    public ResultVO getPatrolPointByTaskId(@PathVariable Integer taskId) {
        List<PatrolPoint> list = patrolPointService.getPatrolPointByTaskId(taskId);
        return ResultVO.success(list);
    }

    @GetMapping("/plan/{planId}")
    public ResultVO getPatrolPointByPlanId(@PathVariable Integer planId) {
        List<PatrolPoint> list = patrolPointService.getPatrolPointByPlanId(planId);
        return ResultVO.success(list);
    }

    @GetMapping("/pointno")
    public ResultVO getPatrolPointByPointNo(@RequestParam String pointNo) {
        PatrolPoint patrolPoint = patrolPointService.getPatrolPointByPointNo(pointNo);
        return ResultVO.success(patrolPoint);
    }
}
